package com.hands.commen.utils;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;

/**
 * 类的描述:
 * 项目名称:   com.smart.life.common.encoder
 * 类的包名:   SmartLifeHost
 * 创建的人:   nongzike@163.com
 * 创建时间:   2019-09-03 16:17
 * 修改的人:   nongzike@163.com
 * 修改时间:   2019-09-03 16:17
 * 修改备注:
 * version   v1.0
 */
public class MyDelimiterBasedFrameDecoder extends DelimiterBasedFrameDecoder {

    //默认分隔符
    public static final String DEFAULT_DELIMITER = "$/r$\r\n";

    public MyDelimiterBasedFrameDecoder() {
        this(1024 * 1024, true, false, Unpooled.copiedBuffer(DEFAULT_DELIMITER.getBytes()));
    }

    public MyDelimiterBasedFrameDecoder(String delimiter) {
        this(1024 * 1024, true, false, Unpooled.copiedBuffer(delimiter.getBytes()));
    }

    public MyDelimiterBasedFrameDecoder(ByteBuf... delimiters) {
        this(1024 * 1024, true, false, delimiters);
    }

    public MyDelimiterBasedFrameDecoder(int maxFrameLength, ByteBuf delimiter) {
        super(maxFrameLength, delimiter);
    }

    public MyDelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, ByteBuf delimiter) {
        super(maxFrameLength, stripDelimiter, delimiter);
    }

    /**
     * maxFrameLength：解码的帧的最大长度
     * stripDelimiter：解码时是否去掉分隔符
     * failFast：为true,当frame长度超过maxFrameLength时立即报TooLongFrameException异常,为false,读取完整个帧再报异常
     * delimiter：分隔符
     */
    public MyDelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, boolean failFast, ByteBuf delimiter) {
        super(maxFrameLength, stripDelimiter, failFast, delimiter);
    }

    public MyDelimiterBasedFrameDecoder(int maxFrameLength, ByteBuf... delimiters) {
        super(maxFrameLength, delimiters);
    }

    public MyDelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, ByteBuf... delimiters) {
        super(maxFrameLength, stripDelimiter, delimiters);
    }

    public MyDelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, boolean failFast, ByteBuf... delimiters) {
        super(maxFrameLength, stripDelimiter, failFast, delimiters);
    }
}
